class MyThread extends Thread{
    @Override
    public void run() {
        while ( true) {
            System.out.println("Thread is running");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class Demo{
    public static void main(String[] args) {

        MyThread t = new MyThread();
        t.start();
        while (true){
            try {
                t.join();
                System.out.println("Main thread is running");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
